<template>
  <!-- 歌单 -->
  <div
    class="m-songList"
    v-title
    :data-title="$t('router.SongListClassicalTitle')"
  >
    <v-nav></v-nav>
    <ul class="tag-lang">
      <li
        v-for="(item, index) of tagList"
        @click="chooseTag(item, index)"
        :class="tagActive == index ? 'active' : ''"
        :key="item.code"
        v-text="$i18n.locale === 'zh' ? item.cname : item.name"
      ></li>
    </ul>
    <div class="main">
      <el-table
        ref="singleTable"
        :data="tableData"
        class="pointer-table scrollbar"
        highlight-current-row
        tooltip-effect="dark"
        @current-change="handleCurrentChange"
        v-loading="fullscreenLoading"
        v-el-table-infinite-scroll="load"
        infinite-scroll-disabled="isPage"
        infinite-scroll-delay="120"
        infinite-scroll-immediate="false"
        height="450"
      >
        <el-table-column
          :label="$t('public.playlistNO')"
          min-width="50%"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
            &nbsp;
            <span
              v-text="
                $i18n.locale == 'zh'
                  ? scope.row.cname || scope.row.name
                  : scope.row.name
              "
            ></span>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('main.creationDate')"
          min-width="50%"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-text="utils.formateDate(scope.row.createTime)"></span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-wrap" v-show="isPage">
      <el-pagination
        @size-change="handlePageSizeChange"
        @current-change="handlePageCurrentChange"
        :current-page="params.pageNum"
        :page-size="params.pageSize"
        background
        hide-on-single-page
        layout="total, prev, pager, next, jumper"
        :total="total"
        small
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import elTableInfiniteScroll from "el-table-infinite-scroll";
import vNav from "@/components/common/header/Nav";
export default {
  directives: {
    "el-table-infinite-scroll": elTableInfiniteScroll,
  },
  data() {
    return {
      tagList: [], //歌单分类列表
      tagActive: 0,
      // 是否显示加载动画
      loading: false,
      // 是否还有数据
      loadStatus: true,
      tableData: [],
      fullscreenLoading: false,
      // 当前选中行
      // currentRow: null,
      // 请求参数
      params: {
        // useType: 3,
        // 返回数量
        pageSize: 30,
        // 当前页数
        pageNum: 1,
        code: "",
      },
      isPage: false, //显示加载更多或分页
      total: 0, //总条数
    };
  },
  components: {
    vNav,
  },
  computed: {},
  watch: {},
  mounted() {
    this.getSongSheetCategory();
  },
  methods: {
    //分页 每页条数
    handlePageSizeChange(val) {
      this.params.pageSize = val;
      this.getSongSheetPage();
    },
    //当前页
    handlePageCurrentChange(val) {
      this.params.pageNum = val;
      this.tableData = [];
      this.getSongSheetPage();
    },
    //获取歌单分类列表
    async getSongSheetCategory() {
      try {
        // let params = {
        //   userId: JSON.parse(localStorage.getItem("userInfo")).userId,
        // }
        let res = await this.$api.classical.getSongSheetCategory({});
        if (res.code === 1000000) {
          this.tagList = res.source ? res.source : [];
          this.params.code = res.source[0].code;
          this.getSongSheetPage();
        }
      } catch (e) {
        console.log(e);
      }
    },
    chooseTag(val, idx) {
      this.tagActive = idx;
      this.fileIndex = 0;
      this.params.code = val.code;
      this.getSongSheetPage();
    },
    //获取歌单
    async getSongSheetPage() {
      this.fullscreenLoading = true;
      try {
        let res = await this.$api.classical.getSongSheetPage(this.params);
        if (res.code === 1000000) {
          this.tableData = res.source ? res.source : [];
          this.total = res.total;
          this.fullscreenLoading = false;
          if (res.size < 50 && res.size < res.total) {
            this.loading = true;
            this.loadStatus = true;
            this.isPage = false;
          } else {
            this.loading = false;
            this.isPage = true;
          }
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 选中触发事件
    handleCurrentChange(val) {
      // this.currentRow = val;
      this.$router.push({
        name: "classicalMSongListDetail",
        params: { id: val.songSheetId + "" },
      });
    },
    // 加载更多
    load() {
      this.params.pageSize += 20;
      this.getSongSheetPage();
    },
  },
};
</script>

<style lang="scss" scoped>
::-webkit-scrollbar {
  width: 0;
  height: 0;
}
</style>
